/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.amu.wmi.kino.visualjavafx.javafxcodegenerators.object;

import java.util.Iterator;
import pl.edu.amu.wmi.kino.visualjavafx.javafxcodegenerators.api.Generator;
import pl.edu.amu.wmi.kino.visualjavafx.javafxcodegenerators.helpergenerators.EndGenerator;
import pl.edu.amu.wmi.kino.visualjavafx.javafxcodegenerators.object.interfaces.Generatable;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.Point;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.path.CurveToPathElement;

/**
 *
 * @author Admin
 */
//TODO : Grzegorz : refactor this [inheritance] when Quad pathElements are in
public class CurveToGenerator implements Generator,Generatable{

    @Override
    public boolean canGenerate(Object c) {
        if(c instanceof CurveToPathElement)
            return true;
        else return false;
    }

    @Override
    public void generate(StringBuilder sb, Object o, int recursionLevel,Object original) {
        this.generateStart(sb);
        this.generatePoints(sb, (CurveToPathElement)o);
        this.generateUniqueAttributes(sb, o,recursionLevel);
        this.generateEnd(sb);
    }

    @Override
    public void generateStart(StringBuilder sb) {
        sb.append("CurveTo{\n");
    }

    @Override
    public void generateEnd(StringBuilder sb) {
        EndGenerator.generateEnd(sb);
    }

    @Override
    public void generateUniqueAttributes(StringBuilder sb, Object o,int recursionLevel) {
         sb.append("absolute:true;\n");
    }

    private void generatePoints(StringBuilder sb,CurveToPathElement c){
        Iterator<Point> iterator=c.getPoints().iterator();
        Point temp = null;
        int counter=1;
        while(iterator.hasNext()){
            temp = iterator.next();
            sb.append("x"+counter+":"+temp.getHPos()+";\n");
            sb.append("y"+counter+":"+temp.getVPos()+";\n");
            counter++;
        }
    }

}
